package com.star.mapper;

import com.github.pagehelper.Page;
import com.star.annotation.AutoFill;
import com.star.dto.CategoryPageQueryDTO;
import com.star.entity.Category;
import com.star.enumeration.OperationType;
import com.star.vo.CategoryVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 新增分类
     * @param category
     */
    @Insert("insert into category(business_id, type, name, status, create_time, update_time, create_user, update_user)" +
            "values (#{businessId}, #{type}, #{name}, #{status}, #{createTime}, #{updateTime}," +
            "#{createUser}, #{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Category category);

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    Page<CategoryVO> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 根据id查询分类
     * @param id
     * @return
     */
    @Select("select * from category where id = #{id}")
    Category getById(Long id);

    /**
     * 动态更新分类信息
     * @param category
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Category category);

    /**
     * 删除分类
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void delete(Long id);

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    List<Category> getByType(Long businessId, Integer type);

    /**
     * 根据商家id查询
     * @param businessId
     * @return
     */
    @Select("select id, name, status, business_id, type from category where status = 1 " +
            "AND business_id = #{businessId}")
    List<Category> getByBusinessId(Long businessId);
}
